package com.dayu.rabbitmq.util;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @author dayu
 * @date 2019/02/19 Describe
 */
public class MQUtil {

    public static Connection getConnection() throws IOException, TimeoutException {
        // 定义一个工厂
        ConnectionFactory factory = new ConnectionFactory();
        // 设置服务地址
        factory.setHost("127.0.0.1");
        // 设置服务端口
        factory.setPort(5672);
        // vhost
        factory.setVirtualHost("/dayu");
        // 用户名
        factory.setUsername("dayu");
        // 密码
        factory.setPassword("dayu");

        return factory.newConnection();
    }
}
